
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;

public class ZhuangMa {
	
	
	public static void main(String[] args){
		//E:\javavido\CDS-BMPD:\MWORK\PERSON\WORKSPACE\CDS-BMP
        File file = new File("D:\\MWORK\\PERSON\\WORKSPACE\\zyezj\\src\\test\\java\\com\\huangwb");
	    getFiileName(file);
   
    }
    
    public static void getFiileName(File file){
    	
        if(file.isDirectory()) {
            File[] subFiles = file.listFiles();
            for(int i = 0 ;i < subFiles.length; i++) {
            	getFiileName(subFiles[i]);
            }
        } else {

        	String fileName = file.getAbsolutePath();
        	String content = readJava(fileName);
        	
        	if(null!=content) {
        		writeFile(fileName,content,"utf-8");
        	}
        	
	
        } 
    }
    public static String readJava(String fileName){
    	
           String str = null;	
           
           int i = fileName.length() -1 ;
           
    	   if("a".equals(fileName.substring(i))){
    		   
	    		File aFile = new File(fileName);
	    		FileInputStream inFile = null;
	    		FileChannel inChannel = null;
	    		ByteBuffer bb = ByteBuffer.allocateDirect(4096);
	    		Charset cs = Charset.forName("GBK");
	    		StringBuffer sb = new StringBuffer(2048);
	    		try{
	    			inFile = new FileInputStream(aFile);
	    		} catch(FileNotFoundException e) {
	    		}
	    		inChannel = inFile.getChannel();
	
	    		try {
	    			while(inChannel.read(bb) != -1) {
	    				bb.flip();
	    				CharBuffer cb = cs.decode(bb);
	    				sb.append(cb.toString());
	    				bb.clear();
	    		}
	    			inFile.close();
	    		} catch(IOException e) {
	    		}
	    		
	    		str = sb.toString();
    		
    		}
    	return str;
    }

    public static void writeFile(String fileName,String content,String encoding){  
    	
    	System.out.println(content);
    	
        try{
        	File f = new File(fileName);
        	if(!f.exists()) {
        		if(!f.getParentFile().exists())
        			f.getParentFile().mkdirs();
        		f.createNewFile();
        	}
            FileChannel out = new FileOutputStream(f).getChannel();  
        
	        out.write(ByteBuffer.wrap(content.getBytes(encoding)));  
	        out.close();  

         }catch(FileNotFoundException e){  
                e.printStackTrace();  
         }catch(IOException e){  
                e.printStackTrace();  
         }  
    }  
    
    
    
    
    	
    }
    
    
    

